﻿layui.use(['element', 'form', 'upload', 'layer', 'slider', 'colorpicker'], function () {
    debugger
    var $ = layui.jquery
       , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    var form = layui.form;
    var slider = layui.slider;
    var colorpicker = layui.colorpicker;
    var data = [];

    //session数据获取
    var itemid = sessionStorage.getItem('itemid');
    var type = sessionStorage.getItem('type');
    var layerw = window.parent.sgworld.ProjectTree.getObject(itemid);
    var CreateType = "";
    if (layerw.item == undefined) {
        return;
    }
    if (type == "polylineLayer") {
        CreateType = "polyline";
        if (layerw.item._primitives[0].appearance != undefined) {
            for (var i = 0; i < layerw.item._primitives.length; i++) {
                var col = layerw.item._primitives[i].appearance.material.uniforms.color.red * 255 + "," + layerw.item._primitives[i].appearance.material.uniforms.color.green * 255 + "," + layerw.item._primitives[i].appearance.material.uniforms.color.blue * 255
                data.push(col);
            }
        } else if (layerw.item._primitives[0]._primitives != undefined && layerw.item._primitives[0]._primitives.length > 0) {
            for (var j = 0; j < layerw.item._primitives.length; j++) {
                for (var i = 0; i < layerw.item._primitives[j]._primitives.length; i++) {
                    var col = layerw.item._primitives[j]._primitives[i].appearance.material.uniforms.color.red * 255 + "," + layerw.item._primitives[j]._primitives[i].appearance.material.uniforms.color.green * 255 + "," + layerw.item._primitives[j]._primitives[i].appearance.material.uniforms.color.blue * 255
                    data.push(col);
                }
            }
        }
    } else if (type == "pointLayer") {
        CreateType = "lable";
        if (layerw.item._primitives[0] != undefined) {
            for (var i = 0; i < layerw.item._primitives.length; i++) {
                var col = layerw.item._primitives[i].appearance.material.uniforms.color.red * 255 + "," + layerw.item._primitives[i].appearance.material.uniforms.color.green * 255 + "," + layerw.item._primitives[i].appearance.material.uniforms.color.blue * 255
                data.push(col);
            }
        } else if (layerw.item._entityCollection._entities != undefined && layerw.item._entityCollection._entities.length > 0) {
            for (var i = 0; i < layerw.item._entityCollection._entities._array.length; i++) {
                var col = layerw.item._entityCollection._entities._array[i]._label._fillColor._value.red * 255 + "," + layerw.item._entityCollection._entities._array[i]._label._fillColor._value.green * 255 + "," + layerw.item._entityCollection._entities._array[i]._label._fillColor._value.blue * 255
                data.push(col);
            }
        }
    }
    data = unique(data);
    DataLoading(data, CreateType, layerw.treeobj.name);
})
//数组去重
function unique(arr) {
    var newArr = []
    for (var i = 0; i < arr.length; i++) {
        if (newArr.indexOf(arr[i]) === -1) {
            newArr.push(arr[i])
        }
    }
    return newArr
}
//数据加载
function DataLoading(data, CreateType, name) {
    var divs = document.getElementById("nc");
    divs.innerHTML = name;
    var div = document.getElementById("sj");
    for (var i = 0; i < data.length; i++) {
        var row = document.createElement('tr');
        var td = document.createElement('td');
        if (CreateType == "polyline") {
            var p = document.createElement('p');
            p.innerHTML = "--";
            p.style.color = "rgb(" + data[i] + ")";
        } else if (CreateType == "lable") {
            var p = document.createElement('p');
            p.innerHTML = "lable";
            //p.style.fontSize = "100px";
            p.style.color = "rgb(" + data[i] + ")";

        }
        td.appendChild(p);
        row.appendChild(td);
        div.appendChild(row);
    }
}
